package com.watson.s2sh.platform.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.watson.s2sh.platform.domain.Menu;
import com.watson.s2sh.platform.domain.MenuItem;

@Transactional
public class MenuDaoImpl implements MenuDao{
	
	@PersistenceContext  
    private EntityManager em;
	
	@Transactional(propagation = Propagation.REQUIRED)  
    public void save(Menu o){  
        em.persist(o);  
    }
      
    @Transactional(propagation = Propagation.REQUIRED)  
    public Menu get(Object id){  
        return em.find(Menu.class, id);  
    }
    
    @Transactional(propagation = Propagation.REQUIRED)  
    public void delete(Menu o){
        em.remove(o);
    }
    
    @Transactional(propagation = Propagation.REQUIRED)  
	public List<Menu> findAllMenu() {
    	Query query = em.createQuery("select m from com.watson.s2sh.platform.domain.Menu m");
		List<Menu> menuList = query.getResultList();
		return menuList;
	}
}
